#include <iostream>
#include <fstream>
#include <cstdio>
#include <json/json.h>
#include "spline.h"

using namespace std;

class X : public Function
{
public:
  double operator()(const double& x) const
  {
    return sqrt(3) * sin(x);
  }
}f1;

class Y : public Function
{
public:
  double operator()(const double& x) const
  {
    return 2.0 / 3 * (sqrt(3) * cos(x) + sqrt(sqrt(3) * fabs(sin(x))));
  }
}f2;

const double pi = acos(-1);
double mx[100];
int main()
{
  ifstream ifs("E.json");
  Json::Reader reader;
  Json::Value obj;
  reader.parse(ifs, obj);
  vector<vector<double>> data;

  FILE* file = nullptr;
  if (freopen_s(&file, "../data/E.out", "w", stdout) != 0) cerr << "error: File opening failure" << endl, exit(-1);
  for (int i = 0;i < obj["n"].size();i++)
    {
      int n = obj["n"][i].asInt();data.clear();
      for (int j = 0;j < n + 1;j++)
        {
	  double theta = pi * 2 * j / n;
	  data.push_back(vector<double>{f1(theta), f2(theta)});
        }
      curve_spline C(data, 3, 1, 1);
      C.solve();
      data = C.get_result();
      for (int i = 0;i < data.size();i++)
        {
	  printf("%lf,", data[i][0]);
        }
      if (i == 0)
	for (int k = 0; k < 30; k++) printf("%lf,", data[i][0]);
      puts("");
      for (int i = 0;i < data.size();i++)
        {
	  printf("%lf,", data[i][1]);
        }
      if (i == 0)
	for (int k = 0; k < 30; k++) printf("%lf,", data[i][1]);
      puts("");
    }
  fclose(stdout);

  return 0;
}
